home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / TERMINAL.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  19KB  |  677 lines

  1. ;***********************;
  2. ; SESSION Terminal Mode ;
  3. ;     By Eric Tauck     ;
  4. ;***********************;
  5.  
  6. FLOWTIME        EQU     91      ;XON timeout, about 5 seconds
  7.  
  8. t_cflg   DB      0      ;non-zero if byte waiting in "t_cbyt"
  9. t_kflg   DB      0      ;non-zero if byte waiting in "t_kbyt"
  10.  
  11. t_mes1  DB      '* Terminal ready at ',0
  12. t_mes2  DB      ' bps on port ',0
  13. t_mes3  DB      13,10,'* Press ALT-X to exit, F1 for help',13,10,0
  14.  
  15. l_err   DB      'Loss of carrier',0
  16.  
  17. x_mes   DB      'Exit Session program',0
  18.  
  19. s_mes   DB      'Session Shell --- Type EXIT to return',0
  20. s_err   DB      'Unable to run shell',0
  21.  
  22. ;--- terminal flags
  23.  
  24. T_ECHO  EQU     0001H   ;local echo
  25. T_SPLIT EQU     0002H   ;split screen
  26. T_SEND  EQU     0004H   ;sending text
  27. T_RECEV EQU     0008H   ;receiving text
  28. T_LINES EQU     0010H   ;add LF's to incomming CR's
  29. T_STRIP EQU     0020H   ;strip high bit from incomming bytes
  30. T_XFAST EQU     0040H   ;fast XMODEM responses
  31. T_X1024 EQU     0080H   ;1024 byte XMODEM blocks
  32. T_ANSI  EQU     0100H   ;ANSI codes enabled
  33. T_CARR  EQU     0200H   ;test carrier
  34. T_OLINE EQU     0400H   ;online flag
  35. T_FILT  EQU     0800H   ;character filter
  36. T_MACRO EQU     1000H   ;running macro
  37. T_DEBUG EQU     2000H   ;display debug info
  38. T_BEGIN EQU     4000H   ;set when macro loaded
  39.  
  40. trmflg  DW      T_XFAST OR T_ANSI OR T_FILT
  41.  
  42. ;--- terminal help text
  43.  
  44. t_help  LABEL   BYTE
  45.         DB      10
  46.         DB      'Session Terminal Commands:',10
  47.         DB      10
  48.         DB      'Control                      Transfer',10
  49.         DB      '-------                      --------',10
  50.         DB      10
  51.         DB      'ALT-A  abort process         PgUp   upload binary file',10
  52.         DB      'ALT-C  clear screen          PgDn   download binary file',10
  53.         DB      'ALT-M  run macro',10
  54.         DB      'ALT-R  reset screen          ALT-U  upload text file',10
  55.         DB      'ALT-X  exit program          ALT-D  download text file',10
  56.         DB      'ALT-Z  system shell',10
  57.         DB      10
  58.         DB      'Configure',10
  59.         DB      '---------',10
  60.         DB      10
  61.         DB      'ALT-E  toggle echo           ALT-B  toggle macro debugging',10
  62.         DB      'ALT-S  toggle split',10
  63.         DB      10
  64.         DB      'Press any key to continue ...',10
  65.         DB      0
  66.  
  67. ;========================================
  68. ; Test carrier flag and set online flag.
  69.  
  70. Test_Line PROC  NEAR
  71.         test    trmflg, T_CARR          ;check if test carrier
  72.         jz      tesonl2                 ;jump if not
  73.         mov     bx, di
  74.         call    ComCar                  ;test carrier
  75.         jc      tesonl2                 ;jump if set
  76.  
  77. ;--- off-line
  78.  
  79.         test    trmflg, T_OLINE         ;check if previously online
  80.         jz      tesonl1                 ;exit if not
  81.         mov     ax, OFFSET l_err        ;message
  82.         call    Command_Error           ;display loss of carrier
  83.         and     trmflg, NOT T_OLINE     ;clear flag
  84. tesonl1 ret
  85.  
  86. ;--- on-line
  87.  
  88. tesonl2 or      trmflg, T_OLINE         ;set flag
  89.         ret
  90.         ENDP
  91.  
  92. ;========================================
  93. ; Check if character should be
  94. ; displayed or not.
  95. ;
  96. ; In: AL= character.
  97. ;
  98. ; Out: CY= set if no display.
  99.  
  100. Char_Filter PROC NEAR
  101.         test    trmflg, T_FILT  ;check if filtered
  102.         jz      chrfil1
  103.         cmp     al, BEL
  104.         je      chrfil1
  105.         cmp     al, BS
  106.         je      chrfil1
  107.         cmp     al, TAB
  108.         je      chrfil1
  109.         cmp     al, LF
  110.         je      chrfil1
  111.         cmp     al, FF
  112.         je      chrfil1
  113.         cmp     al, CR
  114.         je      chrfil1
  115.         cmp     al, 127
  116.         je      chrfil2
  117.         cmp     al, 32
  118.         jb      chrfil2
  119.  
  120. ;--- valid character
  121.  
  122. chrfil1 clc
  123.         ret
  124.  
  125. ;--- invalid character
  126.  
  127. chrfil2 stc
  128.         ret
  129.         ENDP
  130.  
  131. ;========================================
  132. ; Start the pace timer.
  133.  
  134. Pace_Start PROC NEAR
  135.         mov     si, pacetime    ;load delay
  136.         or      si, si          ;check if pacing enabled
  137.         jz      pacsta1         ;exit if not
  138.         mov     al, PACE_TIMER  ;timer number
  139.         call    TicRes          ;reset timer
  140. pacsta1 ret
  141.         ENDP
  142.  
  143. ;========================================
  144. ; Check if within pacing delay.
  145. ;
  146. ; In: SI= current pace count (non-zero
  147. ;     if within delay).
  148. ;
  149. ; Out: CY= set if delayed.
  150.  
  151. Pace_Check PROC NEAR
  152.         or      si, si          ;check if delay
  153.         jz      pacchk1         ;exit if not
  154.         mov     al, PACE_TIMER  ;timer number
  155.         call    TicPas          ;get time passed
  156.         cmp     ax, si          ;check if delayed
  157.         jb      pacchk1         ;exit if so
  158.         sub     si, si          ;zero pace count
  159. pacchk1 ret
  160.         ENDP
  161.  
  162. ;========================================
  163. ; Capture a byte.
  164. ;
  165. ; In: AL= byte.
  166.  
  167. Term_Capture    PROC    NEAR
  168.         test    trmflg, T_RECEV         ;check if receiving
  169.         jz      tercap1                 ;skip if not
  170.         test    trmflg, T_OLINE         ;check if online
  171.         jz      tercap1                 ;skip if not
  172.         call    Text_Write              ;write byte
  173.         jnc     tercap1                 ;jump if okay
  174.         and     trmflg, NOT T_RECEV     ;clear flag on error
  175. tercap1 ret
  176.         ENDP
  177.  
  178. ;========================================
  179. ; Send a local byte in terminal mode.
  180. ;
  181. ; In: AL= character.
  182.  
  183. Term_Out PROC   NEAR
  184.  
  185. ;--- send byte
  186.  
  187.         push    ax
  188.         mov     bx, t_ser
  189.         call    ComPut          ;write character
  190.         pop     ax
  191.  
  192. ;--- echo
  193.  
  194.         call    Char_Filter     ;check if filtered
  195.         jc      trmout2         ;skip echo if so
  196.  
  197.         test    trmflg, T_ECHO OR T_SPLIT
  198.         jz      trmout1
  199.         push    ax
  200.         call    Local_Type      ;display locally
  201.         pop     ax
  202.  
  203.         test    trmflg, T_SPLIT
  204.         jnz     trmout1
  205.         push    ax
  206.         call    Term_Capture    ;capture
  207.         pop     ax
  208.  
  209. trmout1 test    trmflg, T_SPLIT
  210.         jz      trmout2
  211.         cmp     al, CR          ;check if carriage return
  212.         jne     trmout2
  213.         mov     al, LF          ;append linefeed
  214.         call    Local_Type      ;display
  215.  
  216. trmout2 ret
  217.         ENDP
  218.  
  219. ;========================================
  220. ; Receive a remote byte in terminal mode.
  221. ;
  222. ; In: AL= character.
  223.  
  224. Term_Inp PROC   NEAR
  225.  
  226. ;--- check if strip high bit
  227.  
  228.         test    trmflg, T_STRIP ;check if strip high bit
  229.         jz      trminp1
  230.         and     al, NOT 80H     ;clear bit
  231.  
  232. ;--- check for special characters
  233.  
  234. trminp1 test    trmflg, T_OLINE ;check if online
  235.         jz      trminp3
  236.  
  237.         cmp     al, XOFF        ;check if flow control character
  238.         jne     trminp2
  239.         test    trmflg, T_SEND  ;check if sending text
  240.         jz      trminp2
  241.         call    Pause           ;pause
  242.         ret
  243.  
  244. trminp2 cmp     al, ESC         ;check if escape
  245.         jne     trminp3
  246.         test    trmflg, T_ANSI  ;check if ANSI codes
  247.         jz      trminp3
  248.         mov     bx, t_ser
  249.         call    Ansi_Read       ;process ANSI sequence
  250.         ret
  251.  
  252. trminp3 call    Char_Filter     ;check if filtered
  253.         jc      trminp4
  254.  
  255. ;--- display and capture character
  256.  
  257.         push    ax
  258.         call    Remote_Type     ;display
  259.         pop     ax
  260.  
  261.         push    ax
  262.         call    Term_Capture    ;capture
  263.         pop     ax
  264.  
  265.         test    trmflg, T_LINES ;check if append linefeeds
  266.         jz      trminp4
  267.         cmp     al, CR          ;check if carriage return
  268.         jne     trminp4
  269.         mov     al, LF          ;append linefeed
  270.         call    Remote_Type     ;display
  271.         mov     al, LF          ;append linefeed
  272.         call    Term_Capture    ;capture
  273.  
  274. trminp4 ret
  275.         ENDP
  276.  
  277. ;========================================
  278. ; Terminal mode.
  279. ;
  280. ; In: AX= macro file or 0 if none; DI=
  281. ;     serial pointer.
  282.  
  283. Terminal PROC   NEAR
  284.         push    si
  285.         mov     t_ser, di       ;save serial record for global routines
  286.  
  287.         push    ax              ;save macro file
  288.  
  289. ;--- set up screen
  290.  
  291.         mov     ax, OFFSET Screen_Merge
  292.         test    trmflg, T_SPLIT
  293.         jz      term1
  294.         mov     ax, OFFSET Screen_Split
  295. term1   call    ax
  296.  
  297. ;--- sign-on message
  298.  
  299.         StkAll  si, 10                  ;allocate space for numbers
  300.  
  301.         mov     ax, OFFSET banner
  302.         call    System_String
  303.  
  304.         mov     ax, OFFSET t_mes1
  305.         call    System_String
  306.  
  307.         mov     ax, c_speed
  308.         sub     dx, dx
  309.         mov     bx, si
  310.         mov     cx, 10
  311.         call    Num2Str
  312.  
  313.         mov     ax, si
  314.         call    System_String
  315.  
  316.         mov     ax, OFFSET t_mes2
  317.         call    System_String
  318.  
  319.         mov     ax, c_port
  320.         sub     dx, dx
  321.         mov     bx, si
  322.         mov     cx, 10
  323.         call    Num2Str
  324.  
  325.         mov     ax, si
  326.         call    System_String
  327.  
  328.         mov     ax, OFFSET t_mes3
  329.         call    System_String
  330.  
  331.         StkRel  10                      ;fix stack
  332.  
  333.         sub     si, si                  ;zero pace timer
  334.  
  335. ;--- open serial port
  336.  
  337.         mov     al, BYTE c_port
  338.         mov     ah, BYTE c_party
  339.         mov     cl, BYTE c_data
  340.         mov     ch, BYTE c_stop
  341.         mov     dx, c_speed
  342.         mov     bx, di
  343.         call    ComOpn          ;open serial port
  344.  
  345. ;--- load macro file
  346.  
  347.         pop     ax
  348.         or      ax, ax          ;check if macro file passed
  349.         jz      term2
  350.         call    Macro_Load      ;load macro
  351.         jc      term2
  352.         or      trmflg, T_MACRO OR T_BEGIN ;set flags
  353.  
  354. ;=== main terminal loop
  355.  
  356. term2   call    Test_Line       ;check line status first
  357.  
  358. ;--- check for local input
  359.  
  360.         call    KeyGet          ;get keystroke
  361.         jc      term3
  362.         mov     t_kbyt, ax      ;save keystroke
  363.         inc     t_kflg          ;set flag
  364.  
  365. ;--- check for remote input
  366.  
  367. term3   mov     bx, di
  368.         call    ComGet          ;get communications byte
  369.         jc      term4
  370.         mov     t_cbyt, al      ;save byte
  371.         inc     t_cflg          ;set flag
  372.  
  373. ;--- run macro
  374.  
  375. term4   test    trmflg, T_MACRO         ;test if in macro
  376.         jz      term8
  377.  
  378.         test    trmflg, T_DEBUG         ;check if debugging
  379.         jz      term5
  380.         test    trmflg, T_BEGIN         ;check if beginning execution
  381.         jz      term5
  382.         call    DebugInfo               ;display initial debug info
  383.         jc      term7
  384.  
  385. term5   and     trmflg, NOT T_BEGIN     ;clear begin flag
  386.         call    MacRun                  ;run macro
  387.         jc      term6                   ;jump if break
  388.         and     trmflg, NOT T_MACRO     ;clear macro flag
  389.  
  390. term6   test    trmflg, T_DEBUG         ;check if debugging
  391.         jz      term8
  392.         call    DebugInfo               ;display debug info
  393.         jnc     term8
  394.  
  395. term7   and     trmflg, NOT T_MACRO     ;clear macro flag on debug abort
  396.  
  397. ;--- user input
  398.  
  399. term8   cmp     t_kflg, 0       ;check if byte waiting
  400.         je      term9           ;jump if not
  401.  
  402.         dec     t_kflg          ;zero flag
  403.         mov     ax, t_kbyt      ;load keystroke
  404.         or      ah, ah          ;check if extended key
  405.         jnz     termD           ;jump if so
  406.  
  407.         call    Term_Out        ;terminal output
  408.  
  409. ;--- file input
  410.  
  411. term9   test    trmflg, T_SEND  ;check if sending text
  412.         jz      termB
  413.         call    Pace_Check      ;check if in pace delay
  414.         jc      termB
  415.  
  416.         call    Text_Read       ;get a byte
  417.         jc      termE           ;jump if byte unavailable
  418.  
  419.         cmp     al, CR          ;check if end of line
  420.         jne     termA           ;skip if not
  421.         push    ax
  422.         call    Pace_Start      ;restart pacing
  423.         pop     ax
  424.  
  425. termA   call    Term_Out        ;terminal output
  426.  
  427. ;--- remote input
  428.  
  429. termB   cmp     t_cflg, 0       ;check if byte waiting
  430.         je      termC
  431.  
  432.         dec     t_cflg          ;zero flag
  433.         mov     al, t_cbyt
  434.         call    Term_Inp        ;process byte
  435. termC   jmp     term2
  436.  
  437. ;=== terminal exceptions
  438.  
  439. ;--- non-ASCII user key
  440.  
  441. termD   cmp     ax, KEY_ALT_X   ;check if exit
  442.         je      termF           ;jump if so
  443.  
  444.         call    Command         ;do a command
  445.         jmps    term9
  446.  
  447. ;--- failed file read
  448.  
  449. termE   and     trmflg, NOT T_SEND      ;clear flag
  450.         call    Text_Read_End           ;close file
  451.         jmps    termB                   ;goto start of terminal loop
  452.  
  453. ;--- exit terminal mode
  454.  
  455. termF   mov     ax, OFFSET x_mes
  456.         call    Command_Confirm ;confirm close
  457.         jc      term9
  458.  
  459.         call    Text_Write_End  ;close write file
  460.         call    Text_Read_End   ;close read file
  461.         mov     bx, di
  462.         call    ComClo          ;close serial port
  463.         pop     si
  464.         ret
  465.         ENDP
  466.  
  467. ;========================================
  468. ; Set xmodem flags.
  469. ;
  470. ; Out: CL= xmodem flags.
  471.  
  472. Xmodem_Flags PROC       NEAR
  473.         mov     al, XMODEM_CRC  ;always set CRC
  474.         test    trmflg, T_XFAST ;check if fast speed
  475.         jz      xmdflg1
  476.         or      al, XMODEM_FAST ;set flag
  477. xmdflg1 test    trmflg, T_X1024 ;check if big blocks
  478.         jz      xmdflg2
  479.         or      al, XMODEM_BIG  ;set flag
  480. xmdflg2 mov     cl, al
  481.         ret
  482.         ENDP
  483.  
  484. ;========================================
  485. ; Process command.
  486. ;
  487. ; In: AX= command.
  488.  
  489. Command PROC    NEAR
  490.  
  491. ;--- abort something
  492.  
  493.         cmp     ax, KEY_ALT_A           ;check if ALT-A
  494.         jne     commnd3
  495.  
  496.         test    trmflg, T_SEND          ;check if sending text
  497.         jz      commnd1
  498.         call    Text_Read_End           ;close file
  499.         and     trmflg, NOT T_SEND      ;clear flag
  500.         ret
  501.  
  502. commnd1 test    trmflg, T_RECEV         ;check if receiving text
  503.         jz      commnd2
  504.         call    Text_Write_End          ;close file
  505.         and     trmflg, NOT T_RECEV     ;clear flag
  506. commnd2 ret
  507.  
  508. ;--- clear screen
  509.  
  510. commnd3 cmp     ax, KEY_ALT_C   ;check if ALT-C
  511.         jne     commnd4
  512.         call    Clear_Both      ;clear screen
  513.         ret
  514.  
  515. ;--- download
  516.  
  517. commnd4 cmp     ax, KEY_ALT_D   ;check if ALT-D
  518.         jne     commnd6
  519.         sub     ax, ax          ;no file name
  520.         call    Text_Write_Beg  ;start writing
  521.         jc      commnd5         ;jump if error
  522.         or      trmflg, T_RECEV ;set flag
  523. commnd5 ret
  524.  
  525. ;--- toggle echo
  526.  
  527. commnd6 cmp     ax, KEY_ALT_E   ;check if ALT-E
  528.         jne     commnd7
  529.         xor     trmflg, T_ECHO  ;toggle flag
  530.         ret
  531.  
  532. ;--- toggle linefeeds
  533.  
  534. commnd7 cmp     ax, KEY_ALT_L   ;check if ALT-L
  535.         jne     commnd8
  536.         xor     trmflg, T_LINES ;toggle flag
  537.         ret
  538.  
  539. ;--- toggle split screen
  540.  
  541. commnd8 cmp     ax, KEY_ALT_S           ;check if ALT-S
  542.         jne     commndA
  543.         mov     ax, OFFSET Screen_Split ;split routine
  544.         test    trmflg, T_SPLIT         ;check if split
  545.         jz      commnd9                 ;jump if if so
  546.         mov     ax, OFFSET Screen_Merge ;merge routine
  547. commnd9 xor     trmflg, T_SPLIT         ;toggle flag
  548.         call    ax                      ;split or merge
  549.         ret
  550.  
  551. ;--- text upload
  552.  
  553. commndA cmp     ax, KEY_ALT_U   ;check if ALT-U
  554.         jne     commndC
  555.         sub     ax, ax          ;no file name
  556.         call    Text_Read_Beg   ;start reading
  557.         jc      commndB         ;jump if error
  558.         or      trmflg, T_SEND  ;set flag
  559. commndB ret
  560.  
  561. ;--- shell
  562.  
  563. commndC cmp     ax, KEY_ALT_Z   ;check if ALT-Z
  564.         jne     commndD
  565.         call    Shell
  566.         ret
  567.  
  568. ;--- xmodem upload
  569.  
  570. commndD cmp     ax, KEY_PGUP    ;check if page up
  571.         jne     commndE
  572.         call    Xmodem_Flags    ;set flags
  573.         sub     ax, ax          ;no file name
  574.         mov     bx, di
  575.         call    Xmodem_Upload   ;perform upload
  576.         ret
  577.  
  578. ;--- xmodem download
  579.  
  580. commndE cmp     ax, KEY_PGDN    ;check if page down
  581.         jne     commndF
  582.         call    Xmodem_Flags    ;set flags
  583.         sub     ax, ax          ;no file name
  584.         mov     bx, di
  585.         call    Xmodem_Download ;perform download
  586.         ret
  587.  
  588. ;--- help
  589.  
  590. commndF cmp     ax, KEY_F1      ;check if F1
  591.         jne     commndG
  592.         mov     ax, OFFSET t_help
  593.         call    Screen_Display  ;display
  594.         ret
  595.  
  596. ;--- reset screen
  597.  
  598. commndG cmp     ax, KEY_ALT_R   ;check if ALT-R
  599.         jne     commndH
  600.         call    Display_Setup   ;reinitialize screen
  601.         call    Clear_Both      ;clear screen
  602.         ret
  603.  
  604. ;--- run macro
  605.  
  606. commndH cmp     ax, KEY_ALT_M   ;check if ALT-M
  607.         jne     commndJ
  608.         sub     ax, ax          ;no file
  609.         call    Macro_Load      ;load macro
  610.         jc      commndI
  611.         or      trmflg, T_MACRO OR T_BEGIN ;set flags
  612. commndI ret
  613.  
  614. ;--- enable/disable debugging (break)
  615.  
  616. commndJ cmp     ax, KEY_ALT_B   ;check if ALT-B
  617.         jne     commndK
  618.         xor     trmflg, T_DEBUG ;set flag
  619.         ret
  620.  
  621. ;--- invalid command
  622.  
  623. commndK call    Beep_Key        ;beep
  624.         ret
  625.         ENDP
  626.  
  627. ;========================================
  628. ; Execute a command shell.
  629.  
  630. Shell   PROC    NEAR
  631.         call    Screen_Save     ;save the screen
  632.         jc      shell1
  633.         call    Display_Done    ;terminate display
  634.         mov     ax, OFFSET s_mes;message
  635.         call    MesPut          ;display
  636.         call    RunSys          ;switch to DOS shell
  637.         lahf
  638.         push    ax
  639.         call    Display_Init    ;reinitialize display
  640.         call    Screen_Restore  ;restore screen
  641.         pop     ax
  642.         sahf
  643.         jnc     shell1          ;skip if no error
  644.         mov     ax,OFFSET s_err ;error message
  645.         call    Command_Error   ;process error
  646. shell1  ret
  647.         ENDP
  648.  
  649. ;========================================
  650. ; Pause in flow.
  651.  
  652. Pause   PROC    NEAR
  653.  
  654. ;--- reset timer
  655.  
  656. pause1  mov     al, TEMP_TIMER  ;timer to use
  657.         call    TicRes          ;reset timer
  658.         jmps    pause3          ;enter loop
  659.  
  660. ;--- check if timeout
  661.  
  662. pause2  mov     al, TEMP_TIMER  ;timer
  663.         call    TicPas          ;get time passed
  664.         cmp     ax, FLOWTIME    ;check if timeout
  665.         ja      pause4          ;jump if so
  666.  
  667. ;--- check if restart
  668.  
  669. pause3  mov     bx, di
  670.         call    ComGet          ;get byte
  671.         jc      pause2          ;loop back if not
  672.         cmp     al, XOFF        ;check if continue waiting
  673.         je      pause1
  674.  
  675. pause4  ret
  676.         ENDP
  677.